package libaryinterface.admin;

import libaryinterface.admin.AdminDispalyInterface;
import libaryinterface.admin.AdminManageRecordInterface;
import libaryinterface.user.UseinfoInterface;
import libaryinterface.login.LoginInterface;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

public class AdminInterface {
    JFrame f1;
    JPanel p1;
    JButton bmanage,bmessage,bborrow,breturn;
    JLabel label1;
    public AdminInterface() {
        label1 = new JLabel("欢迎来到图书管理系统！");
        f1 = new JFrame("管理员初始界面");
        p1 = new JPanel();
        bmanage = new JButton("书籍管理信息");
        bmessage = new JButton("用户信息管理");
        bborrow = new JButton("借阅管理信息");
        breturn = new JButton("返回登录界面");
        ImageIcon bg = new ImageIcon("src//picture//admin.png");
        JLabel label = new JLabel(bg);
        label.setSize(bg.getIconWidth(),bg.getIconHeight());
        f1.getLayeredPane().add(label,new Integer(Integer.MIN_VALUE));
        //2.把窗口面板设为内容面板并设为透明、流动布局。
        JPanel p1=(JPanel)f1.getContentPane();
        p1.setOpaque(false);
        p1.setLayout((new FlowLayout()));
        p1.setLayout(null);
        label1.setForeground(Color.red);
        label1.setFont(new Font("隶书",Font.PLAIN,35));
        label1.setBounds(30,30,400,50);
        bmanage.setBounds(100, 120, 250, 50);
        bmessage.setBounds(100, 220, 250, 50);
        bborrow.setBounds(100, 320, 250, 50);
        breturn.setBounds(100, 420, 250, 50);
        p1.add(label1);
        p1.add(bmanage);
        p1.add(bmessage);
        p1.add(bborrow);
        p1.add(breturn);
        f1.setVisible(true);
        f1.setBounds(600, 250, 430, 550);
        //书籍管理信息
        bmanage.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    //进入书籍管理界面
                    new AdminDispalyInterface();
                    f1.dispose();
                } catch (SQLException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
        //用户信息管理
        bmessage.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    new UseinfoInterface();
                    f1.dispose();
                } catch (SQLException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
        //借阅管理信息
        bborrow.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new AdminManageRecordInterface();
                    f1.dispose();
                } catch (SQLException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
        breturn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new LoginInterface();
                f1.dispose();
            }
        });
    }
}
